#pragma once
#include <boost/asio.hpp>
#include "MsgNode.h"
class CServer;
class CSession:public std::enable_shared_from_this<CSession>
{
public:
	CSession(boost::asio::io_context& ioc,CServer* server);
	~CSession();
	std::string GetUuid();
	void SetUserId(int uid);
	int GetUserId();
	boost::asio::ip::tcp::socket& GetSocket();
	void Start();
	void Close();
	void Send(std::string, short max_len, short msg_id);
	void Send(char* , short max_len, short msg_id);
private:
	boost::asio::ip::tcp::socket _socket;
	bool _b_stop;
	CServer* _server;
	std::string _session_id;
	std::shared_ptr<MsgNode> _recv_head_node;
	std::shared_ptr<RecvNode>_recv_msg_node;
	std::queue<std::shared_ptr<SendNode>> _send_que;
	std::mutex _mtx;
	char* _data;
	int _user_id;

	void HandleReadHead(const boost::system::error_code& ec,size_t bytes_transferred,std::shared_ptr<CSession>);
	void HandleReadMsg(const boost::system::error_code& ec, size_t bytes_transferred, std::shared_ptr<CSession>);
	void HandleWrite(const boost::system::error_code& ec,std::shared_ptr<CSession>);


};

class LogicNode {
	friend class LogicSys;
public:
	LogicNode(std::shared_ptr<CSession>, std::shared_ptr<RecvNode>);
private:
	std::shared_ptr<RecvNode> _recv_node;
	std::shared_ptr<CSession> _session;
};

